// miniprogram/pages/realName/realName.js

import url from "../../util/url.js"

Page({



  /**
   * 页面的初始数据
   */
  data: {
    userId:'',
    dataRows:[
      { key: 'fee', value: '0.0038', label: '费率', type: 'text', hide: false, die: true },
      { key: 'agencyCode', value: '86038810', label: '机构号', type: 'text', hide: false, die: true },
      { key: 'blicTrcCardNo', value: '', label: '组织机构代码', type: 'text', hide: false, die: true, canNull: true },
      { key: 'blicObaCardNo', value: '', label: '税务登记号', type: 'text', hide: false, die: true, canNull: true },
      { key: 'blicProvince', value: '86038810', label: '营业地址所在省', type: 'text', hide: false, die: true },
      { key: 'blicCity', value: '86038810', label: '营业地址所在市', type: 'text', hide: false, die: true },

      {
        key: 'companyType', value: { value: 'N', label: '个人' }, label: '商户类型', type: 'pick', picks: [
          { value: 'N', label: '个人' },
          { value: 'P', label: '个体工商户' },
          { value: 'E', label: '企业' }
        ], hide: false
      },
      {
        key: 'privatePublic', value: {}, label: '结算类型', type: 'pick', picks: [
          { value: 1, label: '对公' },
          { value: 0, label: '对私-法人' },
          { value: 3, label: '对私-非法人' }
        ], hide: false
      },

      { key: 'regPhone', value: '', label: '手机号', type: 'input', hide: false  },
      { key: 'regEmail', value: '', label: '邮箱', type: 'input', hide: false },
      
      {
        key: 'bankName', value: {}, label: '结算银行名称', type: 'pick', picks: [
          { value: '中国工商银行', label: '中国工商银行' },
          { value: '中国农业银行', label: '中国农业银行' },
          { value: '中国银行', label: '中国银行' },
          { value: '中国建设银行', label: '中国建设银行' },
          { value: '交通银行', label: '交通银行' },
          { value: '中国邮政储蓄银行', label: '中国邮政储蓄银行' },
          { value: '中信银行', label: '中信银行' },
          { value: '华夏银行', label: '华夏银行' },
          { value: '中国民生银行', label: '中国民生银行' },
          { value: '广东发展银行', label: '广东发展银行' },
          { value: '平安银行', label: '平安银行' },
          { value: '招商银行', label: '招商银行' },
          { value: '兴业银行', label: '兴业银行' },
          { value: '是浦东发展银行', label: '是浦东发展银行' },
          { value: '渤海银行', label: '渤海银行' },
          { value: '其他银行', label: '其他银行' },
        ],  hide: false },
      { key: 'subBankCode', value: {}, label: '结算银行支行', type: 'pick', hide: false  },
      { key: 'bankAccountNo', value: '', label: '结算银行卡账号', type: 'input', hide: false },
      { key: 'settleCardPhone', value: '', label: '结算银行卡绑定手机号', type: 'input', hide: false },
      { key: 'bankAccountName', value: '', label: '结算账户名', type: 'input', hide: false },
      { key: 'settleCertificate', value: '', label: '结算人身份证号码', type: 'input', hide: false },
      { key: 'settlerCertificateStartDate', value: '', label: '结算人身份证有效期（起始）', type: 'date', hide: false },
      { key: 'settlerCertificateEndDate', value: '', label: '结算人身份证有效期（截止）', type: 'date', hide: false, isLong: false, showIsLogin: true },
      { key: 'abMerchantName', value: '', label: '商户简称', type: 'input' },
      { key: 'blicCompanyName', value: '', label: '门店名称', type: 'input', hide: false },
      { key: 'blicAddr', value: '', label: '门店所在地', type: 'region', hide: false },
      { key: 'blicAddress', value: '', label: '详细经营地址', type: 'input', hide: false },
      {
        key: 'indTwoCode', value: {}, label: '所属行业', type: 'pick', picks: [
          { label: '线下零售', value: '070' },
          { label: '餐饮/食品', value: '072' },
          { label: '休闲娱乐', value: '147' },
          { label: '医疗', value: '073' },
          { label: '教育培训', value: '075' },
          { label: '生活缴费', value: '172' },
          { label: '公益', value: '109' },
          { label: '电商/团购', value: '029' },
          { label: '自助加油站', value: '174' },
          { label: '其他类型', value: '076' },
          { label: '互联网系统服务', value: '024' },
          { label: '酒店/民宿预订', value: '030' },
          { label: '在线娱乐', value: '032' },
          { label: 'OTA平台', value: '033' },
          { label: '票务', value: '034' },
          { label: '网上生活服务平台(O2O)', value: '040' },
          { label: '医疗服务平台', value: '042' },
          { label: '婚介交友/咨询服务/婚庆/汽车保养/娱乐休闲/广告设计/宠物服务/衣物保养/维修服务', value: '043' },
          { label: '互联网系统服务', value: '024' },
          { label: '自助售卖机', value: '053' },
        ], hide: false
      },

      { key: 'blicCardType', value: {}, label: '证照类型', type: 'pick', picks: [
          { value: 'USC', label: '统一社会信用代码类' },
          { value: 'BLI', label: '普通五证类' },
          { value: 'OCI', label: '多证合一类' }, 
          { value: 'USC', label: '统一社会信用代码类' },
          { value: 'BLI', label: '普通营业执照' }
        ], hide: false
      },

      { key: 'blicUscc', value: '', label: '营业执照号', type: 'input', hide: false  },
      { key: 'blicValidityStart', value: '', label: '营业执照有效期', type: 'date', hide: false },
      { key: 'blicValidityEnd', value: '', label: '营业执照有效期截止', type: 'date', hide: false, isLong: false,showIsLogin: true },

      {
        key: 'lepCardType', value: { value: 'ID', label: '身份证' }, label: '法人证件类型', type: 'pick',picks:[
        { value: 'ID', label:'身份证'},
        { value: 'PAS', label: '护照' },
        { value: 'PASTW', label: '台胞证' },
        { value: 'PASHK', label: '港澳居民来往通行证' },
      ], hide: false },
      { key: 'lepName', value: '', label: '法人证件中姓名', type: 'input', hide: false },
      { key: 'lepCardNo', value: '', label: '法人证件中号码', type: 'input', hide: false },
      { key: 'lepValidityStart', value: '', label: '法人证件起始日', type: 'date', hide: false},
      { key: 'lepValidityEnd', value: '', label: '法人证件到期日', type: 'date', hide: false, isLong: false, showIsLogin: true },

      // { key: 'comment', value: '', label: '备注', type: 'input', hide: false, canNull: true },
    ],

    rowInexMap:{

    },

    photoIndexMap:{

    },

    photos:[],

    allPhotos:[
      {
        img: '../../images/shengfenzhengzhengmian.png',
        label: '法人身份证信息正面图片',
        key: 'lepUrla',
        hide: false
      },
      {
        img: '../../images/guohuimian.png',
        label: '法人身份证信息背面图',
        key: 'lepUrlb',
        hide: false
      },
      {
        img: '../../images/guohuimian.png',
        label: '法人手持法人身份证照片',
        key: 'lepUrlc',
        hide: false
      },
      {
        img: '../../images/shengfenzhengzhengmian.png',
        label: '经营门店门头照片',
        key: 'img',
        hide: false
      },
      {
        img: '../../images/guohuimian.png',
        label: '经营门店店内照片',
        key: 'innerimg',
        hide: false
      },
      {
        img: '../../images/shengfenzhengzhengmian.png',
        label: '入账授权书',
        key: 'settleProtocol',
        hide: false
      },
      {
        img: '../../images/shengfenzhengzhengmian.png',
        label: '结算人身份证正面照',
        key: 'settleManPhotoFront',
        hide: false
      },
      {
        img: '../../images/shengfenzhengzhengmian.png',
        label: '结算人身份证背面照',
        key: 'settleManPhotoBack',
        hide: false
      },
      {
        img: '../../images/shouchi.png',
        label: '结算人手持身份证正面',
        key: 'settleHoldingIDCard',
        hide: false
      },
      {
        img: '../../images/chuxuka.png',
        label: '结算银行卡正面照图片',
        key: 'cardPhoto',
        hide: false
      },
      {
        img: '../../images/chuxuka.png',
        label: '结算人手持银行卡照片',
        key: 'settleHoldingBankCard',
        hide: false
      },
      {
        img: '../../images/shouchi.png',
        label: '营业执照',
        key: 'blicUrla',
        hide: false
      },
      {
        img: '../../images/chuxuka.png',
        label: '经营门店出入口照片',
        key: 'enterimg',
        hide: false
      },
      {
        img: '../../images/chuxuka.png',
        label: '税字号图片',
        key: 'blicObaUrla',
        hide: false
      },
      {
        img: '../../images/chuxuka.png',
        label: '组织机构代码证图片',
        key: 'blicTrcUrla',
        hide: false
      },
      {
        img: '../../images/chuxuka.png',
        label: '银行开户许可证图片',
        key: 'occUrla',
        hide: false
      }
    ]
  },

  takePhoto:function(e){
    let i = e.currentTarget.dataset.i;
    let j = e.currentTarget.dataset.j;
    wx.chooseImage({
      count:1,
      success: res => {
        this.data.photos[i][j].img = res.tempFiles[0].path;
        wx.getFileSystemManager().readFile({
          filePath: res.tempFiles[0].path,
          success: data => {
            this.data.photos[i][j].value = Array.prototype.slice.call(new Uint8Array(data.data))
            this.setData({
              photos: this.data.photos
            })
            
          }
        })
      }
    })
  },

  submit:function(e){
    // wx.chooseMessageFile({
    //   count: 6,
    //   type: 'all',
    //   success(res) {
    //     var tempFilePaths = res.tempFiles;
    //     var filename = tempFilePaths[0].name;
    //     wx.getFileSystemManager().readFile({
    //       filePath: tempFilePaths[0].path,
    //       success: fileStream => {
    //         var fileArray = new Uint8Array(fileStream.data);
    //         var start_boundary = '\r\n–yourboundary\r\n' + 'Content-Disposition:form-data; name ="data; filename= "' + 'yourfilename'+ '"\r\n'+'Content-Type:application/octet-stream' +'\r\n\r\n';
    //         var end_boundary = '\r\n–yourboundary–';
    //         var startArray = [];
    //         for (var i = 0; i < start_boundary.length; i++) {
    //           startArray.push(start_boundary.charCodeAt(i));
    //         }
    //         var endArray = [];
    //         for (var i = 0; i < end_boundary.length; i++) {
    //           endArray.push(end_boundary.charCodeAt(i));
    //         }
    //         var totalArray = startArray.concat(Array.prototype.slice.call(fileArray), endArray);
    //         var typedArray = new Uint8Array(totalArray);
    //         console.log(typedArray.buffer)
    //         wx.request({
    //           url: 'http://58.82.248.252:9090/notice/tUserInformation/shiming',
    //           method: 'POST',
    //           header: {
    //             'content-type': 'multipart/form-data; boundary=yourboundary'
    //           },
    //           data: typedArray.buffer,
    //           success: function (res) {
    //           }
    //         })
    //       }
    //     })}
    //   })
    for(var i = 0;i < this.data.dataRows.length;i++){
      var row = this.data.dataRows[i]
      if (!row.hide && (row.value == null || row.value.length == 0) && !row.canNull){
        wx.showToast({
          title: row.label + '不能为空',
          icon:'none'
        })
        return
      }
    }

    for (var i = 0; i < this.data.length; i++) {
      var row = this.data.dataRows[i]
      if (!row.hide && (!row.value || row.value.length == 0) && !row.canNull) {
        wx.showToast({
          title: row.label + '不能为空',
          icon: 'none'
        })
        return
      }
    }

    let data = '';
    let key = '';
    let value = '';
    for (let i = 0; i < this.data.dataRows.length;i++){
      let item = this.data.dataRows[i];
      if (item.hide || !item.value) {
        continue
      }
      key = item.key;
      if (item.type === 'pick'){
        value = item.value.value
      }else{
        value = item.value;
      }

      if (key == 'blicAddress'){
        let addr = this.data.dataRows[this.data.rowInexMap.blicAddr].value
        let as = addr.split(' ')
        value += as[0] + as[1] + as[2]
      }
      
      
      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + key + '"' +
        '\r\n' +
        '\r\n' + value
    }
    if (this.data.dataRows[this.data.rowInexMap.companyType].value.value == 'N'){
      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'blicCardType' + '"' +
        '\r\n' +
        '\r\n' + 'ID'

      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'lepCardType' + '"' +
        '\r\n' +
        '\r\n' + 'ID'

      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'blicValidityStart' + '"' +
        '\r\n' +
        '\r\n' + this.data.dataRows[this.data.rowInexMap.settlerCertificateStartDate].value

      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'blicValidityEnd' + '"' +
        '\r\n' +
        '\r\n' + this.data.dataRows[this.data.rowInexMap.settlerCertificateEndDate].value

      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'privatePublic' + '"' +
        '\r\n' +
        '\r\n' + 0

      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'privatePublic' + '"' +
        '\r\n' +
        '\r\n' + 0

      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'lepName' + '"' +
        '\r\n' +
        '\r\n' + this.data.dataRows[this.data.rowInexMap.bankAccountName].value

      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'lepCardNo' + '"' +
        '\r\n' +
        '\r\n' + this.data.dataRows[this.data.rowInexMap.settleCertificate].value 

      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'lepValidityStart' + '"' +
        '\r\n' +
        '\r\n' + this.data.dataRows[this.data.rowInexMap.settlerCertificateStartDate].value  

      data += '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="' + 'lepValidityEnd' + '"' +
        '\r\n' +
        '\r\n' + this.data.dataRows[this.data.rowInexMap.settlerCertificateEndDate].value


    }

    data += '\r\n--XXX' +
      '\r\nContent-Disposition: form-data; name="' + 'serialNo' + '"' +
      '\r\n' +
      '\r\n' + Date.parse(new Date())

    data += '\r\n--XXX' +
      '\r\nContent-Disposition: form-data; name="' + 'userId' + '"' +
      '\r\n' +
      '\r\n' + this.data.userId
    

    var array = this.stringToByte(data)

    for (let i = 0; i < this.data.photos.length; i++) {
      for (let j = 0; j < this.data.photos[i].length; j++){
        let item = this.data.photos[i][j];
        if (item.hide || !item.value || item.value.length == 0) {
          continue
        }
       
        key = item.key;
        array = array.concat(this.stringToByte('\r\n--XXX'))
        array = array.concat(this.stringToByte('\r\nContent-Disposition: form-data; name="' + key + '";filename="' + key + '"'))
        array = array.concat(this.stringToByte('\r\n\r\n'))
        array = array.concat(item.value)

        if (key == 'settleManPhotoFront' && this.data.dataRows[this.data.rowInexMap.companyType].value.value == 'N'){
          array = array.concat(this.stringToByte('\r\n--XXX'))
          array = array.concat(this.stringToByte('\r\nContent-Disposition: form-data; name="' + 'lepUrla' + '";filename="' + 'lepUrla' + '"'))
          array = array.concat(this.stringToByte('\r\n\r\n'))
          array = array.concat(item.value)
        }

        if (key == 'settleManPhotoBack' && this.data.dataRows[this.data.rowInexMap.companyType].value.value == 'N') {
          array = array.concat(this.stringToByte('\r\n--XXX'))
          array = array.concat(this.stringToByte('\r\nContent-Disposition: form-data; name="' + 'lepUrlb' + '";filename="' + 'lepUrlb' + '"'))
          array = array.concat(this.stringToByte('\r\n\r\n'))
          array = array.concat(item.value)
        }

        if (key == 'settleHoldingIDCard' && this.data.dataRows[this.data.rowInexMap.companyType].value.value == 'N') {
          array = array.concat(this.stringToByte('\r\n--XXX'))
          array = array.concat(this.stringToByte('\r\nContent-Disposition: form-data; name="' + 'lepUrlc' + '";filename="' + 'lepUrlc' + '"'))
          array = array.concat(this.stringToByte('\r\n\r\n'))
          array = array.concat(item.value)
        }

      }
    }

   array = array.concat(this.stringToByte('\r\n--XXX'))
   wx.showLoading({
     title: '',
     mask: true
   })
    wx.request({
      url: url.realName,
      method: 'POST',
      header:{
        'content-type': 'multipart/form-data; boundary=XXX'
      },
      data: new Uint8Array(array).buffer,
      success: res => {
        console.log(res);
        wx.showModal({
          title: '提示',
          content: res.data && res.data.message ? res.data.message : res.data,
          showCancel: false
        })
      },
      fail: () => {
        wx.showToast({
          title: '认证失败',
          icon: 'none'
        })
      },
      complete: () =>{
        wx.hideLoading()
      }
    })
  },

  stringToByte:function (str) {
    var bytes = new Array();
    var len, c;
    len = str.length;
    for(var i = 0; i<len; i++) {
      c = str.charCodeAt(i);
      if (c >= 0x010000 && c <= 0x10FFFF) {
        bytes.push(((c >> 18) & 0x07) | 0xF0);
        bytes.push(((c >> 12) & 0x3F) | 0x80);
        bytes.push(((c >> 6) & 0x3F) | 0x80);
        bytes.push((c & 0x3F) | 0x80);
      } else if (c >= 0x000800 && c <= 0x00FFFF) {
        bytes.push(((c >> 12) & 0x0F) | 0xE0);
        bytes.push(((c >> 6) & 0x3F) | 0x80);
        bytes.push((c & 0x3F) | 0x80);
      } else if (c >= 0x000080 && c <= 0x0007FF) {
        bytes.push(((c >> 6) & 0x1F) | 0xC0);
        bytes.push((c & 0x3F) | 0x80);
      } else {
        bytes.push(c & 0xFF);
      }
    }
    return bytes;
  },

  byteToString:function (arr) {
      if (typeof arr === 'string') {
        return arr;
      }
      var str = '',
        _arr = arr;
      for (var i = 0; i < _arr.length; i++) {
        var one = _arr[i].toString(2),
          v = one.match(/^1+?(?=0)/);
        if (v && one.length == 8) {
          var bytesLength = v[0].length;
          var store = _arr[i].toString(2).slice(7 - bytesLength);
          for (var st = 1; st < bytesLength; st++) {
            store += _arr[st + i].toString(2).slice(2);
          }
          str += String.fromCharCode(parseInt(store, 2));
          i += bytesLength - 1;
        } else {
          str += String.fromCharCode(_arr[i]);
        }
      }
      return str;
  },

  bindDataChange:function(e){

    let target = e.currentTarget;
    let value = e.detail.value;
    let index = target.dataset.index;
    let item = target.dataset.item;
    let row = this.data.dataRows[index];

    switch(item.type){
      case 'input':
        row.value = value
        break;
      case 'date':
      //长期checkbox的value是数组
        if (value.length != 1){
          row.value = value
          row.isLong = false
        }else{
          if (row.isLong){
            row.isLong = false
            row.value = null
          }else{
            row.isLong = true
            row.value = '长期'
          }
        }
        
        break;
      case 'pick':
        row.value = row.picks[value]
        row.currPick = value
        if (row.key === 'bankName'){
          this.requestBank(row.value.value)
        }
        break;
      case 'radio':
        row.value = value
        break;
      case 'region':
        row.value = value[0] + ' ' + value[1] + ' ' + value[2];
        row.codes = e.detail.code;
        break;
    }
    this.refreshData();
  },

  requestBank(bankName){
    wx.request({
      url: url.bank,
      data: { bankName: bankName, bankCodeName: ''},
      success:(res) => {
        for(let i = 0;i < res.data.length;i++){
          res.data[i].value = res.data[i].bankCode
          res.data[i].label = res.data[i].bankName
        }
        this.data.dataRows[this.data.rowInexMap.subBankCode].picks = res.data
        this.data.dataRows[this.data.rowInexMap.subBankCode].value = {}
        this.setData({
          dataRows: this.data.dataRows
        })
      }
    })
  },

  refreshData(){
    let companyType = this.data.dataRows[this.data.rowInexMap.companyType].value.value
    let privatePublic = this.data.dataRows[this.data.rowInexMap.privatePublic].value.value //对公，对私-法人，对私-非法人 1，0，3
    let blicCardType = this.data.dataRows[this.data.rowInexMap.blicCardType].value || ''

  
    //门店所在地
    let addr = this.data.dataRows[this.data.rowInexMap.blicAddr].value
    if (addr){
      let as = addr.split(' ')
      this.data.dataRows[this.data.rowInexMap.blicProvince].value = as[0]
      this.data.dataRows[this.data.rowInexMap.blicCity].value = as[1]
    }

    this.data.dataRows[this.data.rowInexMap.lepName].hide = companyType == 'N'
    this.data.dataRows[this.data.rowInexMap.lepCardNo].hide = companyType == 'N'
    this.data.dataRows[this.data.rowInexMap.lepValidityStart].hide = companyType == 'N'
    this.data.dataRows[this.data.rowInexMap.lepValidityEnd].hide = companyType == 'N'
    this.data.dataRows[this.data.rowInexMap.settleCertificate].hide = companyType != 'N'

    if (companyType == 'N'){
      this.data.dataRows[this.data.rowInexMap.blicUscc].hide = true
      this.data.dataRows[this.data.rowInexMap.blicValidityStart].hide = true
      this.data.dataRows[this.data.rowInexMap.blicValidityEnd].hide = true
      this.data.dataRows[this.data.rowInexMap.blicCardType].hide = true
      this.data.dataRows[this.data.rowInexMap.privatePublic].hide = true
      this.data.dataRows[this.data.rowInexMap.lepCardType].hide = true

      this.data.dataRows[this.data.rowInexMap.blicUscc].value = ''
      this.data.dataRows[this.data.rowInexMap.blicValidityStart].value = ''
      this.data.dataRows[this.data.rowInexMap.blicValidityEnd].value = ''
      this.data.dataRows[this.data.rowInexMap.blicCardType].value = ''
      this.data.dataRows[this.data.rowInexMap.privatePublic].value = ''
    }else{
      this.data.dataRows[this.data.rowInexMap.blicUscc].hide = false
      this.data.dataRows[this.data.rowInexMap.blicValidityStart].hide = false
      this.data.dataRows[this.data.rowInexMap.blicValidityEnd].hide = false
      this.data.dataRows[this.data.rowInexMap.blicCardType].hide = false
      this.data.dataRows[this.data.rowInexMap.privatePublic].hide = false
    }

    this.data.dataRows[this.data.rowInexMap.blicObaCardNo].value = this.data.dataRows[this.data.rowInexMap.blicUscc].value
    this.data.dataRows[this.data.rowInexMap.blicTrcCardNo].value = this.data.dataRows[this.data.rowInexMap.blicUscc].value
    
    
    this.data.allPhotos[this.data.photoIndexMap.blicUrla].label = companyType === 'N' ? '租赁合同照片' : '营业执照'

    this.data.allPhotos[this.data.photoIndexMap.lepUrla].hide = companyType === 'N'
    this.data.allPhotos[this.data.photoIndexMap.lepUrlb].hide = companyType === 'N'
    this.data.allPhotos[this.data.photoIndexMap.lepUrlc].hide = companyType === 'N'

    this.data.allPhotos[this.data.photoIndexMap.lepUrla].label = companyType === 'E' ? '法人身份证信息正面图片' : '店主身份证信息正面图片'
    this.data.allPhotos[this.data.photoIndexMap.lepUrlb].label = companyType === 'E' ? '法人身份证信息背面图片' : '店主身份证信息背面图片'
    this.data.allPhotos[this.data.photoIndexMap.lepUrlc].label = companyType === 'E' ? '法人手持法人身份证照片' : '店主手持法人身份证照片'

    this.data.allPhotos[this.data.photoIndexMap.occUrla].hide = privatePublic != 1
    this.data.allPhotos[this.data.photoIndexMap.blicObaUrla].hide = blicCardType != 'BLI'
    this.data.allPhotos[this.data.photoIndexMap.blicTrcUrla].hide = blicCardType != 'BLI'
    this.data.allPhotos[this.data.photoIndexMap.settleProtocol].hide = privatePublic != 3  
    this.data.allPhotos[this.data.photoIndexMap.settleManPhotoFront].hide = privatePublic != 3 && companyType != 'N'
    this.data.allPhotos[this.data.photoIndexMap.settleManPhotoBack].hide = privatePublic != 3 && companyType != 'N'
    this.data.allPhotos[this.data.photoIndexMap.settleHoldingIDCard].hide = privatePublic != 3 && companyType != 'N'
    this.data.allPhotos[this.data.photoIndexMap.cardPhoto].hide = privatePublic != 3 && privatePublic != 0 && companyType != 'N'
    this.data.allPhotos[this.data.photoIndexMap.settleHoldingBankCard].hide = privatePublic != 3
   
    
  
    let k = 0,j = 0;
    let array = [];
    for (let i = 0; i < this.data.allPhotos.length; i++) {
      let item = this.data.allPhotos[i];
      if (!array[k]){
        array[k] = []
      }
      if(!item.hide){
        array[k][j] = item;
        j = (j + 1) % 2
        if (j == 0) {
          k++
        }
      }
    }

    this.setData({
      dataRows:this.data.dataRows,
      photos: array
    })
    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getStorage({
      key: 'userId',
      success: (res) => {
        this.setData({
          userId: res.data
        })
      }
    })
    let obj1 = {}
    for(let i = 0;i < this.data.dataRows.length;i++){
       let item = this.data.dataRows[i];
      obj1[item.key] = i;
    }
    let obj2 = {}
    for (let i = 0; i < this.data.allPhotos.length; i++) {
      let item = this.data.allPhotos[i];
      obj2[item.key] = i;
    }
    
    this.setData({
      rowInexMap: obj1,
      photoIndexMap: obj2
    },() => {
      this.refreshData()
    }) 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})